﻿using System;
using System.Linq;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.AIModule.Pet.Expedition
{
    public class ExpeditionRecord : DbBaseEntity
    {
        public string UserID { get; set; }

        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime EndTime { get; init; }

        public string Scene { get; init; }

        /// <summary>
        /// 是否已领取奖励
        /// </summary>
        public bool IsDrawn { get; set; }
    }

    public static class ExpeditionRecordDA
    {
        public static bool IsExpediting(this ExpeditionRecord entity)
        {
            return DateTime.Now < entity.EndTime;
        }

        public static ExpeditionRecord GetLastest(string UserID)
        {
            return MongoService<ExpeditionRecord>.Get(p => p.UserID == UserID, p => p.EndTime, false, 0, 1).FirstOrDefault();
        }

        public static void Insert(this ExpeditionRecord entity)
        {
            MongoService<ExpeditionRecord>.Insert(entity);
        }

        public static void Update(this ExpeditionRecord entity)
        {
            MongoService<ExpeditionRecord>.Update(entity);
        }
    }
}